package com.giscloud.commons.model;

import com.giscloud.commons.enums.ResultEnum;
import lombok.Data;
import lombok.ToString;
import lombok.extern.log4j.Log4j2;

/**
 * @Author:giscloud
 * @Description:
 * @Date: 9:13 2019/9/12
 * @Modified By:
 */
@Data
@ToString
@Log4j2
public class Result<T> {

    /**
     * 响应结果 成功/失败
     */
    private Boolean success;
    /**
     * 状态响应码
     */
    private Integer code;

    /**
     * 提示信息
     */
    private String msg;

    /**
     * 返回数据
     */
    private T data;

    public static Result success(Object object) {
        Result result = new Result();
        result.setSuccess(Boolean.TRUE);
        result.setCode(ResultEnum.SUCCESS.getCode());
        result.setMsg(ResultEnum.SUCCESS.getMsg());
        result.setData(object);
        return result;
    }

    public static Result success(String msg) {
        Result result = new Result();
        result.setSuccess(Boolean.TRUE);
        result.setCode(ResultEnum.SUCCESS.getCode());
        result.setMsg(msg);
        result.setData(null);
        return result;
    }
    public static Result success(Object object,String msg) {
        Result result = new Result();
        result.setSuccess(Boolean.TRUE);
        result.setCode(ResultEnum.SUCCESS.getCode());
        result.setMsg(msg);
        result.setData(object);
        return result;
    }

    public static Result success() {
        return success("success");
    }

    public static Result error(int code, String msg) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(msg);
        result.setSuccess(Boolean.FALSE);
        return result;
    }

    public static Result error(ResultEnum resultEnum) {
        Result result = new Result();
        result.setCode(resultEnum.getCode());
        result.setMsg(resultEnum.getMsg());
        result.setSuccess(Boolean.FALSE);
        return result;
    }

    public static Result error(String msg) {
        Result result = new Result();
        result.setCode(ResultEnum.FAIL.getCode());
        result.setMsg(msg);
        result.setSuccess(Boolean.FALSE);
        return result;
    }
}
